package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.db.domain.MarketCollectExample;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 付诚
 * @Date: 2024/5/19 19:05
 * @Description:
 */
@Service
public class MarketCollectServiceImpl implements MarketCollectService {

    @Autowired
    private MarketCollectMapper marketCollectMapper;

    @Override
    public List<MarketCollect> list(Integer page, Integer limit, String userId, String valueId, String sort, String order) {

        MarketCollectExample marketCollectExample = new MarketCollectExample();
        marketCollectExample.setOrderByClause(sort + " " + order);
        MarketCollectExample.Criteria criteria = marketCollectExample.createCriteria();
        if (!StringUtils.isEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        }
        if (!StringUtils.isEmpty(valueId)) {
            criteria.andValueIdEqualTo(Integer.parseInt(valueId));
        }

        //两个参数：当前页；每页数量
        PageHelper.startPage(page, limit);

        List<MarketCollect> marketCollectList = marketCollectMapper.selectByExample(marketCollectExample);
        return marketCollectList;
    }
}
